home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ksocks.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.2 KB  |  211 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 2001 George Staikos <staikos@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef _KSOCKS_H_
  19. #define _KSOCKS_H_
  20.  
  21. #include <qstringlist.h>
  22. #include <sys/types.h>
  23. #include <sys/time.h>
  24. #include <kstaticdeleter.h>
  25. #include <kdelibs_export.h>
  26.  
  27. #ifdef Q_OS_UNIX
  28.  
  29. class KSocksTable;
  30. class KSocksPrivate;
  31. class KLibrary;
  32. class KConfigBase;
  33. struct sockaddr;
  34.  
  35. typedef unsigned ksocklen_t;
  36.  
  37.  
  38. /**
  39.  * This class provides you with an interface to a 
  40.  * <a href="http://www.socks.nec.com/">SOCKS</a> Proxy server. A SOCKS server
  41.  * is able to provide full internet access behind a firewall.
  42.  * KSocks is a singleton; there can only be one instance at any
  43.  * given time. To obtain a reference to that instance, use
  44.  * self().
  45.  *
  46.  * @short Access to a SOCKS Proxy.
  47.  */
  48. class KDECORE_EXPORT KSocks {
  49.    friend class KStaticDeleter<KSocks>;
  50.  
  51. public:
  52.  
  53.    /**
  54.     * Return an instance of class KSocks *.
  55.     * You cannot delete this object.  It is a singleton class.
  56.     * @return the KSock instance
  57.     */
  58.    static KSocks *self();
  59.  
  60.    /**
  61.     * Checks whether KSocks has been started (ie someone called self())
  62.     * @return true if activated
  63.     */
  64.    static bool activated();
  65.  
  66.    /**
  67.     * Disable the use of SOCKS immediately
  68.     */
  69.    void disableSocks();
  70.  
  71.    /**
  72.     * Enable the use of SOCKS immediately if hasSocks() is true.
  73.     */
  74.    void enableSocks();
  75.  
  76.    /**
  77.     * Checks whether SOCKS is currently being used.
  78.     * @return true if SOCKS is currently being used.
  79.     */
  80.    bool usingSocks();
  81.  
  82.    /**
  83.     * Checks whether SOCKS is available for use.
  84.     * @return true if SOCKS is available for use.
  85.     */
  86.    bool hasSocks();
  87.  
  88.    /**
  89.     * Returns whether asynchronous connects work with the
  90.     * selected SOCKS impementation
  91.     */
  92.    bool hasWorkingAsyncConnect();
  93.  
  94.    /*
  95.     **     REIMPLEMENTATIONS OF LIBC SOCKET FUNCTIONS
  96.     **/
  97.    /**
  98.     * This is the re-implementation of libc's function of the same
  99.     * name. Read the appropriate man page.
  100.     */
  101.     int     connect     (int sockfd, const sockaddr *serv_addr, 
  102.                                 ksocklen_t addrlen);
  103.    /**
  104.     * This is the re-implementation of libc's function of the same
  105.     * name. Read the appropriate man page.
  106.     */
  107.     signed long int read  (int fd, void *buf, unsigned long int count);
  108.    /**
  109.     * This is the re-implementation of libc's function of the same
  110.     * name. Read the appropriate man page.
  111.     */
  112.     signed long int write (int fd, const void *buf, unsigned long int count);
  113.    /**
  114.     * This is the re-implementation of libc's function of the same
  115.     * name. Read the appropriate man page.
  116.     */
  117.     int     recvfrom    (int s, void *buf, unsigned long int len, int flags, 
  118.                                 sockaddr *from, ksocklen_t *fromlen);
  119.    /**
  120.     * This is the re-implementation of libc's function of the same
  121.     * name. Read the appropriate man page.
  122.     */
  123.     int     sendto      (int s, const void *msg, unsigned long int len, int flags,
  124.                              const sockaddr *to, ksocklen_t tolen);
  125.    /**
  126.     * This is the re-implementation of libc's function of the same
  127.     * name. Read the appropriate man page.
  128.     */
  129.     int     recv        (int s, void *buf, unsigned long int len, int flags);
  130.    /**
  131.     * This is the re-implementation of libc's function of the same
  132.     * name. Read the appropriate man page.
  133.     */
  134.     int     send        (int s, const void *msg, unsigned long int len, int flags);
  135.    /**
  136.     * This is the re-implementation of libc's function of the same
  137.     * name. Read the appropriate man page.
  138.     */
  139.     int     getsockname (int s, sockaddr *name, ksocklen_t *namelen);
  140.    /**
  141.     * This is the re-implementation of libc's function of the same
  142.     * name. Read the appropriate man page.
  143.     */
  144.     int     getpeername (int s, sockaddr *name, ksocklen_t *namelen);
  145.    /**
  146.     * This is the re-implementation of libc's function of the same
  147.     * name. Read the appropriate man page.
  148.     */
  149.     int     accept      (int s, sockaddr *addr, ksocklen_t *addrlen);
  150.    /**
  151.     * This is the re-implementation of libc's function of the same
  152.     * name. Read the appropriate man page.
  153.     */
  154.     int     select      (int n, fd_set *readfds, fd_set *writefds, 
  155.                                 fd_set *exceptfds, struct timeval *timeout);
  156.    /**
  157.     * This is the re-implementation of libc's function of the same
  158.     * name. Read the appropriate man page.
  159.     */
  160.     int     listen      (int s, int backlog);
  161.  
  162.    /**
  163.     * This is the re-implementation of libc's function of the same
  164.     * name. Read the appropriate man page.
  165.     */
  166.     int     bind        (int sockfd, sockaddr *my_addr, 
  167.                                      ksocklen_t addrlen);
  168.     int     bind        (int sockfd, const sockaddr *my_addr, 
  169.                                      ksocklen_t addrlen);
  170.  
  171.     /**
  172.     *  If you're using this, you're probably doing something wrong.
  173.     *  Please don't use it.
  174.     * @internal
  175.     */
  176.    void die();
  177.  
  178.    /**
  179.     *  Set this before the first call to KSocks::self() and it will fail
  180.     *  to initialize SOCKS.
  181.     */
  182.    static void disable();
  183.  
  184.    /**
  185.     *  Set this before the first call to KSocks::self() and it will use
  186.     *  @p config to read its configuration from.
  187.     */
  188.    static void setConfig(KConfigBase *config);
  189.  
  190. private:
  191.    KSocks(KConfigBase *config);
  192.    ~KSocks();
  193.  
  194.    void stopSocks();
  195.  
  196.    static KSocks *_me;
  197.    static bool _disabled;
  198.    QStringList _libNames;
  199.    QStringList _libPaths;
  200.    bool _useSocks, _hasSocks;
  201.    KLibrary* _socksLib;
  202.  
  203.  
  204.    KSocksTable *_st;
  205.    KSocksPrivate *d;
  206. };
  207.  
  208. #endif //Q_OS_UNIX
  209.  
  210. #endif //_KSOCKS_H_
  211.